home *** CD-ROM | disk | FTP | other *** search
/ Software 2000 / Software 2000 Volume 1 (Disc 1 of 2).iso / utilities / u286.dms / u286.adf / Misc / Size.SRC / Size.SRC
Text File  |  1991-07-21  |  10KB  |  274 lines

  1.     opt l-,c+,a+,p+    ;Executable,case-sensitive,auto PC,position independent
  2.     
  3. ;{ ---------- Program name:- Window_Sizer ---------------------------------------------------------------------------- }
  4.  
  5. ;{ ---------- Program Version 1.00 ----------------------------------------------------------------------------------- }
  6.  
  7. ;{ ---------- Where to find include files ---------------------------------------------------------------------------- }
  8.  
  9.     incdir    "dh0:Hi-Soft/Include/"
  10.  
  11. ;{ ---------- Include files required --------------------------------------------------------------------------------- }
  12.  
  13.     include    exec/exec_lib.i
  14.     include    intuition/intuition_lib.i
  15.     include    intuition/intuitionbase.i
  16.     include    intuition/intuition.i
  17.     include    libraries/dos_lib.i
  18.     include    libraries/dos.i
  19.  
  20. ;{----------- Macro CALLSYS ------------------------------------------------------------------------------------------ }
  21.  
  22. CALLSYS MACRO
  23.             JSR    _LVO\1(A6)
  24.             ENDM
  25.  
  26. ;{----------- Defintions used in the program ------------------------------------------------------------------------- }
  27.  
  28. IntB            EQU        -4                ;Reserved for intuition base address (long)
  29. DosB            EQU        -8                ;Reserved for dos base address (long)
  30. WdAdd            EQU        -12                ;Reserved for window base address (long)
  31.  
  32. TopOfWindow        EQU        -14                ;
  33. LeftEdge        EQU        -16                ;Reserved for new window parameters
  34. Width            EQU        -18                ;(word)
  35. Height            EQU        -20                ;
  36.  
  37. Mul            EQU        -22                ;Multiplication factor (m.f.)
  38.  
  39. ;{----------- Open required libraries -------------------------------------------------------------------------------- }
  40.  
  41. Start            link        a5,#-22                ;Reserve user stack space
  42.             movem.l        d0/a0,-(sp)            ;Save parameter data on system stack
  43.  
  44. OpenLibraries        moveq.l        #33,d0                ;
  45.             lea        IntName,a1            ;Open intuition library version 1.2 or greater
  46.             CALLEXEC    OpenLibrary            ;
  47.             move.l        d0,IntB(a5)            ;
  48.             beq        Error_No_Int            ;
  49.  
  50.             moveq.l        #33,d0                ;
  51.             lea        DosName,a1            ;Open dos library version 1.2 or greater
  52.             CALLSYS        OpenLibrary            ;
  53.             move.l        d0,DosB(a5)            ;
  54.             beq        Error_No_Dos            ;
  55.  
  56. ;{----------- Routines ---------------------------------------------------------------------------------------------- }
  57.  
  58. ;{----------- Get window base address ------------------------------------------------------------------------------- }
  59.  
  60.             move.l        IntB(a5),a0            ;
  61.             move.l        ib_ActiveWindow(a0),d0        ;Get the address for the active window
  62.             beq        Error_No_Window            ;
  63.             move.l        d0,WdAdd(a5)            ;Save the base address
  64.             movem.l        (sp)+,d0/a0            ;Get parameter address back from stack                
  65.  
  66. ;{----------- Get Parameters ---------------------------------------------------------------------------------------- }
  67.  
  68.             cmp.b        #1,d0                ;See if any parameters passed
  69.             beq.s        No_Parameters            ;Go set default values
  70.             adda.l        d0,a0                ;
  71.             subq        #1,a0                ;
  72. Return            cmp.b        #"?",-1(a0)            ;
  73.             beq        Help                ;Display help screen
  74.             cmp.b        #"s",-1(a0)            ;
  75.             beq.s        Small                ;
  76.             clr.l        d6                ;
  77.             bsr.s        Get                ;
  78.             move.w        d7,Height(a5)            ;Calculate and store parameters for
  79.             cmp.w        #256,d7                ;
  80.             bhi.s        JumpEm                ;
  81.             bsr.s        Get                ;window positioning
  82.             move.w        d7,Width(a5)            ;
  83.             cmp.w        #640,d7                ;
  84.             bhi.s        JumpEm                ;
  85.             bsr.s        Get                ;
  86.             move.w        d7,TopOfWindow(a5)        ;
  87.             cmp.w        Height(a5),d7            ;
  88.             bcc.s        JumpEm                ;
  89.             move.l        #1,d6                ;
  90.             bsr.s        Get                ;
  91.             move.w        d7,LeftEdge(a5)            ;
  92.             cmp.w        Width(a5),d7            ;
  93.             bcc.s        JumpEm                ;
  94.  
  95. Cont            bra        Main                ;
  96.  
  97. JumpEm            bra        ErrorMess            ;Branch to error message routine
  98.  
  99. ;{----------- Present Screen Sizes --------------------------------------------------------------------------------- }
  100.  
  101. No_Parameters        move.w        #0,TopOfWindow(a5)        ;
  102.             move.w        #0,LeftEdge(a5)            ;Values for maximum window
  103.             bra.s        BottomCorner            ;
  104.  
  105. Small            move.w        #255,TopOfWindow(a5)        ;
  106.             move.w        #639,LeftEdge(a5)        ;Values for minimum window
  107. BottomCorner        move.w        #640,Width(a5)            ;
  108.             move.w        #256,Height(a5)            ;
  109.             bra.s        Cont
  110.  
  111. ;{----------- Check Current Parameter ------------------------------------------------------------------------------ }
  112.  
  113. Get            clr.l        d1                ;Setup variables required for routine
  114.             clr.l        d7                ;
  115.             move.w        #1,Mul(a5)            ;Set m.f. to 1
  116. Search            subi        #1,d0                ;
  117.             cmp.b        #$20,-(a0)            ;Skip spaces in parameter line
  118.             bne.s        Again                ;
  119.             cmp        #0,d0                ;
  120.             bne.s        Search                ;
  121. Again            bsr.s        Test                ;
  122.             cmp.b        #0,d2                ;See if present digit is valid
  123.             beq.s        Skip                ;Branch if o.k.
  124.             cmp.b        #1,d2                ;
  125.             beq.s        End                ;
  126.             cmp.b        #1,d6                ;
  127.             bne.s        ErrorMess                ;Check error not caused by end of
  128.             cmp.b        #0,d0                ;parameter list
  129.             beq.s        End                ;
  130.             bra.s        ErrorMess            ;
  131. Skip            muls        Mul(a5),d1            ;Multiply digit by multiplication factor
  132.             add.w        d1,d7                ;Add to running total
  133.             move.w        Mul(a5),d3            ;
  134.             muls        #10,d3                ;Make m.f.:=m.f. * 10
  135.             move.w        d3,Mul(a5)            ;
  136.             cmp.w        #1000,d3            ;See if all three digits have been processed
  137.             bne.s        Again                ;No
  138. End            rts                        ;
  139.  
  140. ;{----------- Test Present Digit ------------------------------------------------------------------------------------ }
  141.  
  142. Test            cmp.b        #$20,(a0)            ;Check of current number has finished
  143.             beq.s        Fin                ;
  144.             cmp.b        #"0",(a0)            ;
  145.             blt.s        Error                ;See if digit is in allowed range
  146.             cmp.b        #"9",(a0)            ;
  147.             bhi.s        Error                ;
  148.             move.b        (a0),d1                ;Convert digit from ASCII to absolute
  149.             subi        #48,d1                ;
  150.             subi        #1,d0                ;
  151.             suba        #1,a0                ;
  152.             clr.b        d2                ;
  153.             rts                        ;
  154.  
  155. Error            move.b        #2,d2                ;Invalid parameter error
  156.             rts                        ;
  157.  
  158. Fin            move.b        #1,d2                ;End of current number
  159.             rts                        ;
  160.  
  161. ;{----------- Error Message Display --------------------------------------------------------------------------------- }
  162.  
  163. ErrorMess        lea        Error_Mess,a2            ;Get details on error message and display
  164.             move.l        a2,d2                ;it on active window. (Keep position indi)
  165.             move.l        #Error_Mess_Len,d3        ;
  166.             bra.s        Display                ;
  167.  
  168. ;{----------- Help display ------------------------------------------------------------------------------------------ }
  169.  
  170. Help            lea        Help_Text,a2            ;Get details on help text and display it on
  171.             move.l        a2,d2                ;the active window
  172.             move.l        #Help_Text_Len,d3        ;(Keep position indipendent)
  173.             
  174. ;{----------- Display requested text ------------------------------------------------------------------------------- }
  175.  
  176. Display                        
  177.             move.l        DosB(a5),a6            ;Get output window address through DOS
  178.             CALLSYS        Output                ;
  179.             move.l        d0,d1                ;
  180.             CALLSYS        Write                ;Display Message
  181.  
  182. ;{----------- Close open libraries ---------------------------------------------------------------------------------- }
  183.  
  184. CloseLibraries
  185.  
  186. Error_No_Window        move.l        DosB(a5),a1            ;Close dos library
  187.             CALLEXEC    CloseLibrary            ;
  188. Error_No_Dos        move.l        IntB(a5),a1            ;Close graphics library
  189.             CALLSYS        CloseLibrary            ;
  190.  
  191. Error_No_Int        unlk        a5                ;Destroy user stack
  192.             rts                        ;Go home
  193.  
  194. ;{----------- Zero window ------------------------------------------------------------------------------------------- }
  195.  
  196. Zero_Window        move.l        WdAdd(a5),a0            ;Restore active window base address
  197.             clr.l        d0                ;
  198.             sub.w        wd_LeftEdge(a0),d0        ;Calculate offset to move window to 0,0
  199.             clr.l        d1                ;
  200.             sub.w        wd_TopEdge(a0),d1        ;
  201.             bra.s        Test_Window            ;
  202.  
  203. ;{----------- Move the window --------------------------------------------------------------------------------------- }
  204.  
  205. Move_Window        move.l        WdAdd(a5),a0            ;Restore active window base address
  206.             clr.l        d0                ;Clear the two data registers
  207.             clr.l        d1                ;
  208.             move.w        LeftEdge(a5),d0            ;
  209.             sub.w        wd_LeftEdge(a0),d0        ;Calculate the offset to move the window
  210.             move.w        TopOfWindow(a5),d1        ;
  211.             sub.w        wd_TopEdge(a0),d1        ;
  212. Test_Window        tst.w        d0                ;
  213.             bne.s        Move_It                ;Only move window if required
  214.             tst.w        d1                ;
  215.             beq.s        Return1                ;
  216.  
  217. Move_It            move.l        IntB(a5),a6            ;Call move window routine
  218.             CALLSYS        MoveWindow            ;
  219. Return1            bra.s        Wait                ;
  220.  
  221. ;{----------- Size the window --------------------------------------------------------------------------------------- }
  222.  
  223. Size_Window        move.l        WdAdd(a5),a0            ;Restore active window base address
  224.             clr.l        d0                ;Clear two data registers
  225.             clr.l        d1                ;
  226.             move.w        Width(a5),d0            ;
  227.             sub.w        wd_Width(a0),d0            ;Calculate offset for sizing window
  228.             sub.w        LeftEdge(a5),d0            ;
  229.             move.w        Height(a5),d1            ;
  230.             sub.w        wd_Height(a0),d1        ;
  231.             sub.w        TopOfWindow(a5),d1        ;
  232.             tst.w        d0                ;
  233.             bne.s        Size_It                ;Only size window if required
  234.             tst.w        d1                ;
  235.             beq.s        Wait                ;
  236.  
  237. Size_It            move.l        IntB(a5),a6            ;
  238.             CALLSYS        SizeWindow            ;Call size window routine
  239.  
  240.  
  241. ;{----------- Delay ------------------------------------------------------------------------------------------------- }
  242.  
  243. Wait            move.l        DosB(a5),a6            ;
  244.             move.l        #$05,d1                ;Give small delay between moving and sizing
  245.             CALLSYS        Delay                ;the window
  246.             rts                        ;
  247.  
  248. ;{----------- Main -------------------------------------------------------------------------------------------------- }
  249.  
  250. Main            
  251.             bsr.s        Zero_Window            ;Move window to 0,0
  252.             bsr.s        Size_Window            ;Make window required size
  253.             bsr.s        Move_Window            ;Move window to required position
  254.             bra         CloseLibraries            ;Close the libraries openned
  255.  
  256. ;{----------- Error Message ----------------------------------------------------------------------------------------- }
  257.  
  258. Error_Mess        dc.b    $a,'Bad Args.',$a,$a
  259.             
  260. Error_Mess_Len        equ    *-Error_Mess
  261.  
  262. ;{----------- Help text --------------------------------------------------------------------------------------------- }
  263.  
  264. Help_Text        dc.b    $a,'Written By Steve White. January 1990.',$a,$a
  265.             dc.b    'Usage:- Size [s] [LeftEdge TopEdge RightEdge BottomEdge]',$a,$a
  266.             dc.b    'Enjoy!!',$a,$a
  267. Help_Text_Len        equ    *-Help_Text
  268.  
  269. ;{----------- Library names from include files ---------------------------------------------------------------------- }
  270.  
  271. IntName            INTNAME
  272.  
  273. DosName            DOSNAME
  274.